Skip to content

Scorecard Integration #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 68 commits into
base: main
Choose a base branch
from

Conversation

404-geek
Copy link
Collaborator

@404-geek 404-geek commented Jun 26, 2024

ScoreCode Integration

This pull request integrates the ScoreCode Repo into SCIO, enabling the fetching of the latest OSSF Scorecard Data for discovered packages using their vcs_url. The current implementation supports github.com and gitlab.com VCS URLs.

Key Features:

  • Integration with ScoreCode Repo
  • Fetching of OSSF Scorecard Data using vcs_url
  • Support for github.com and gitlab.com VCS URLs

Related Issues:

This feature enhances SCIO's functionality by ensuring that users can retrieve the most up-to-date security scores for packages discovered in their projects, improving overall security assessment and management.

404-geek added 30 commits June 26, 2024 13:20
developed functions to check for availability nexB#598

Signed-off-by: 404-geek <[email protected]>
Signed-off-by: 404-geek <[email protected]>
Signed-off-by: 404-geek <[email protected]>
…gration

# Conflicts:
#	scanpipe/models.py
#	scanpipe/tests/test_models.py
@pombredanne
Copy link
Member

@404-geek can you check the failing tests?

@tdruez
Copy link
Contributor

tdruez commented Oct 29, 2024

Hey @404-geek , what's your latest status on this PR? Any chances we can complete and merge it before it diverges too much from the main branch?

@404-geek
Copy link
Collaborator Author

Hey @404-geek , what's your latest status on this PR? Any chances we can complete and merge it before it diverges too much from the main branch?

Hi @tdruez,

I’m planning to have this PR ready by next week. Most of the requested changes have been addressed; I just need to add a few test cases before pushing the final version.

Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@404-geek See my various comments ;)

Also, the new pipeline needs to be added to the built-in-pipelines.rst documentation.

)

@classmethod
@transaction.atomic()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@404-geek You haven't address the question above yet ;)

@404-geek 404-geek requested a review from tdruez March 2, 2025 06:46
Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also suggest to simplify the pipeline and module names:

  • fetch_scorecode_info -> fetch_scores
  • FetchScoreCodeInfo -> FetchScores

@@ -128,6 +130,7 @@ dev =
android_analysis =
android_inspector==0.0.1


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Comment on lines +1265 to +1267
package1.discovered_packages_score.filter(scoring_tool="ossf-scorecard")[
0
].score,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put package1.discovered_packages_score.filter(scoring_tool="ossf-scorecard")[0] in a variable for better readability.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could we test on the real value in place of assertIsNotNone?

msg=out,
)

self.assertEqual("https://github.com/ossf/scorecard", package1.vcs_url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why test this value here since it was set earlier in the test? Is it expected to change?

@@ -1238,6 +1238,38 @@ def test_scanpipe_find_vulnerabilities_pipeline_integration(
expected = vulnerability_data[0]["affected_by_vulnerabilities"]
self.assertEqual(expected, package1.affected_by_vulnerabilities)

@mock.patch("scorecode.ossf_scorecard.is_available")
def test_scanpipe_get_scorecard_info_packages_integration(self, mock_is_available):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test depends on internet access at the moment. This is problematic.
The ossf_scorecard.fetch_scorecard_info return value should be mocked instead.

Comment on lines +173 to +177
scorecard_data_file.parent.mkdir(parents=True, exist_ok=True)

scorecard_data_file.write_text(json.dumps(scorecard_data, indent=2))

print(f"Scorecard data successfully saved to {scorecard_data_file}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be outside the try block.

return None

@classmethod
@transaction.atomic()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove in this context.

Comment on lines +4424 to +4431
@classmethod
def create_from_package_and_scorecard(cls, scorecard_data, package):
score_object = cls.create_from_scorecard_data(
discovered_package=package,
scorecard_data=scorecard_data,
scoring_tool="ossf-scorecard",
)
return score_object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one really useful?
It seems to create complexity around create_from_scorecard_data with simply defining a scoring_tool value.
I would suggested to get rid of it and define a default value for the scoring_tool:

def create_from_scorecard_data(
        cls, discovered_package, scorecard_data, scoring_tool="ossf-scorecard"
    ):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why the scoring_tool is not part of the scorecard_data?
It seems weird to allow to overwrite the scoring_tool value from the parameter but still taking the tool_version and docuementation_url from the scorecard_data.

package=package, scorecard_data=scorecard_obj
)

self.assertIsNotNone(package_score)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test on real values.

Comment on lines +2625 to +2626
if check.check_score == "-1":
self.assertEqual(check.check_score, "-1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the goal here?

package=package, scorecard_data=scorecard_obj
)

# Step 4: Retrieve the first check that was automatically created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting at 4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store OSSF scorecard data in scancode.io models Enrich an SBOM using OSSF Security Score Card
4 participants